<template>
  <div class="tenant">
    <hunk-head customEvent="true" @headFn="gobanck" name="租客入住"></hunk-head>
    <div class="content">
      <hunk-list class="flex1" :list="houseList" @clickitem="clickitem" @clickBtn="clickBtn" @onRefresh="onRefresh" @searchInput= "searchInput"></hunk-list>
    </div>
  </div>
</template>

<script>
import Head from '@componentsMine/head'
import List from '@componentsMine/list'
import { getHouseList } from '@/apis/housesInfo'
export default {
  components: {
    'hunk-head': Head,
    'hunk-list': List
  },
  data() {
    return {
      addresslike: '',  //模糊查询
      houseattribute: [],  // 出租方式 0-自持 1-托管
      housetype: [],  // 0-空 1-已租 2-欠租 3-接近交租 4-租约快到期 5-未绑定门锁
      outtype: [],  //出租方式 0-合租 1-整租
      houseList: [],
    }
  },
  computed: {
    userid(){
      return this.$store.state.baseStore.userInfo.userid
    }
  },
  onshow(){
    this.getHouseList()
  },
  created(){
    this.getHouseList()
    if (this.$store.state.baseStore.userInfo.usertype == 1) { 
      if(wx.createInterstitialAd){
        this.interstitialAd = wx.createInterstitialAd({ adUnitId: 'adunit-b7624e2779b6167a' })
        this.interstitialAd.onLoad(() => {
          console.log('onLoad event emit')
        })
        this.interstitialAd.onError((err) => {
          console.log('onError event emit', err)
        })
        this.interstitialAd.onClose((res) => {
          console.log('onClose event emit', res)
        })
      }
      this.interstitialAd.show().then().catch(err => {
        console.log(err)
      })
    }
         
  },
  methods: {
    gobanck(){
      uni.redirectTo({ url: '/pages/index/index' })
    },
    onRefresh(){
      this.getHouseList()
    },
    searchInput(item){
      this.addresslike = item
      this.getHouseList()
    },
    clickitem(item) {
      if(item.isitem != 0 && item.tag == 0 ){
        this.$jump({path: '/subPackage/manage/commponents/tenant/setLease?query=' + JSON.stringify(item)})
      }else{
        if(item.tag != 0 && item.isitem != 0){
          uni.showToast({
            title: '已出租房源,无法入住',
            icon: 'none'
          })
        }else{
          uni.showToast({
            title: '未绑定门锁,无法入住',
            icon: 'none'
          })
        }
      }
      
    },
     clickBtn(item){
      let arr = item.split(',')
      this[arr[0]] = arr
      this[arr[0]].shift()
      this.getHouseList()
    },
    getHouseList(){
      const data = {
        addresslike: this.addresslike,  //模糊查询
        houseattribute: this.houseattribute,  // 出租方式 0-自持 1-托管
        housetype: this.housetype,  // 0-空 1-已租 2-欠租 3-接近交租 4-租约快到期 5-未绑定门锁
        outtype: this.outtype,   //出租方式 0-合租 1-整租
        userid: this.userid
      }
      getHouseList(data).then(res=>{
        if(res.code == 200){
          if(!res.data){
            this.houseList = []
            return
          }
          this.houseList = res.data
        }
      })
    },
  }
}
</script>

<style lang="scss" scoped>
.tenant{
  width: 100vw;
  box-sizing: border-box;
  height: 100vh;
  background: #F9F9F9;
  display: flex;
  flex-direction: column;
  .content{
    flex: 1;
    display: flex;
    overflow-y: auto
  }
  .flex1{
    flex: 1;
    display: flex;
  }
}
</style>
